//
//  MainTabbarViewController.m
//  DDFish
//
//  Created by 糖otk on 2017/8/1.
//  Copyright © 2017年 Burining. All rights reserved.
//

#import "MainTabbarViewController.h"
#import "MainNaviViewController.h"
#import "HomeViewController.h"
#import "SingerViewController.h"
#import "UserViewController.h"
#import "HotViewController.h"
@interface MainTabbarViewController ()
@end

@implementation MainTabbarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupChildVcs];
    [self setupTabBar];
    [self setupUI];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setupUI {
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
    attributes[NSForegroundColorAttributeName] = [UIColor grayColor];
    attributes[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    
    NSMutableDictionary *selectAttri = [NSMutableDictionary dictionary];
    selectAttri[NSForegroundColorAttributeName] = NaviBarGroundColor;
    selectAttri[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    UITabBarItem *tabbar = [UITabBarItem appearance];
    
    [tabbar setTitleTextAttributes:attributes forState:UIControlStateNormal];
    [tabbar setTitleTextAttributes:selectAttri forState:UIControlStateSelected];
    
    UIView *view = [UIView new];
    view.frame = self.tabBar.bounds;
    view.backgroundColor = RGB_COLOR(251, 251, 251);
    [self.tabBar insertSubview:view atIndex:0];
}

- (void)setupTabBar
{
    self.tabBar.translucent = NO;
//    self.automaticallyAdjustsScrollViewInsets = false;

}

- (void)setupChildVcs {
    [self setupChildVc:[HomeViewController new] title:@"首页" image:@"tabbar-home" selectedImage:@"tabbar-home-high"];
    [self setupChildVc:[SingerViewController new] title:@"热门" image:@"tabbar-order" selectedImage:@"tabbar-order-high"];
    [self setupChildVc:[HotViewController new] title:@"歌手" image:@"tabbar-huanzhe" selectedImage:@"tabbar-huanzhe-high"];
    [self setupChildVc:[UserViewController new] title:@"我的" image:@"tabbar-me" selectedImage:@"tabbar-me-high"];
}


- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    // 包装一个导航控制器
    MainNaviViewController *nav = [[MainNaviViewController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
    
    // 设置子控制器的tabBarItem
    nav.tabBarItem.title = title;
    nav.tabBarItem.image = [UIImage imageNamed:image];
    nav.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
   
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    
    
}
@end
